// pages/payorder/payorder.js
const api = require("../../api/api")
const app = getApp()
Page({

    /**
     * 页面的初始数据
     * 
     */
    data: {
      id: '', //当前选择商品订单的id
      goodsDetailMsg: [],
      img: [],
      time:0,
      price:0,
      buyer_id:'', //目前登录者的ID
      sender_id:'',//发布该商品订单的人的ID
      commentor:[],
      commentorImg:'',
      commentorNickName:''
      
    },
    getGoods() {
      wx.request({
            url: api.getGoodsDetail.url,
            method: api.getGoodsDetail.method,
            data: {
              id: this.data.id,
            },
            success: res => {
              console.log(res)
              var info = res.data.data[0].img.split('|')
              this.setData({
                goodsDetailMsg: res.data.data[0],
                time:res.data.data[0].viewCount,
                img:info,
                price: parseInt(res.data.data[0].price)*100,
                sender_id:res.data.data[0].senderId
              })
              console.log(this.data.goodsDetailMsg)
              console.log(this.data.img)
            },
        })
    },

    onLoad: function (options) {
      console.log(options)
      wx.request({
        url: api.getComment.url,
        method:api.getComment.method,
        data:{
          id:options.goodsId
        },
        success:res=>{ 
        console.log(res)
        var list = res.data.data
        var temp = this.data.commentor
        for (let index = 0; index < list.length; index++) {
         temp.push(list[index])          
        }
        this.setData({
          commentorImg:res.data.data[0].avatarUrl,
          commentorNickName:res.data.data[0].nickName,
          commentor:temp
        })
        console.log(this.data.commentor)
        }
      })
      this.setData({
        id: options.goodsId,
        buyer_id:app.globalData.id
      })
      this.getGoods()     
    },
   
})